package com.zaydanwu.cla.service.Impl;

import com.zaydanwu.cla.dao.CommentMapper;
import com.zaydanwu.cla.model.Comment;
import com.zaydanwu.cla.model.result.CommentResult;
import com.zaydanwu.cla.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @BelongsProject: cla
 * @BelongsPackage: com.zaydanwu.cla.service.Impl
 * @Author: zaydanwu
 * @CreateTime: 2019-01-05 15:20
 * @Description:
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentMapper commentMapper;

    @Override
    public int saveComment(Comment record) {
        return commentMapper.insert(record);
    }

    @Override
    public CommentResult getAllComment(Integer newId) {
        CommentResult commentResult = new CommentResult();
        List<Comment> comments = commentMapper.selectAll(newId);
        commentResult.setCommentList(comments);
        int i = commentMapper.selectCount(newId);
        commentResult.setCommentCount(i);
        return commentResult;
    }
}
